drop _all
capture log close
set mem 4g
set more off
set virtual on
use world_child3
set logtype text
log using world-lowess-country, replace

***********************************
*****	THIS DO FILE:
***********************************

* 1) produces lowess graph of predicted infant mort against mother ht, for 20% of observations for pooled sample.

***********************************
*****	MODIFY DATA FOR USE
***********************************

** keep only children with full exposure

tab infant_exp
keep if infant_exp==1

drop if imputed_height<120 | imputed_height>180

* have now removed these outliers - need to make sure this is made clear in the paper
count

gen height100=imputed_height/100
preserve

***********************************
*****	LOWESS
***********************************

sort countryid

* (1)

foreach num of numlist 1/38 {
	lowess infant height100 if countryid==`num', generate(infpred`num') 
	graph export lowess-country-`num'.png, replace
	}

twoway (line infpred1 height100, sort) (line infpred2 height100, sort) (line infpred3 height100, sort) (line infpred4 height100, sort) (line infpred5 height100, sort) (line infpred6 height100, sort) (line infpred7 height100, sort) (line infpred8 height100, sort) (line infpred9 height100, sort) (line infpred10 height100, sort) (line infpred11 height100, sort) (line infpred12 height100, sort)(line infpred13 height100, sort) (line infpred14 height100, sort) (line infpred15 height100, sort) (line infpred16 height100, sort) (line infpred17 height100, sort) (line infpred18 height100, sort) (line infpred19 height100, sort) (line infpred20 height100, sort) (line infpred21 height100, sort) (line infpred22 height100, sort) (line infpred23 height100, sort) (line infpred24 height100, sort) (line infpred25 height100, sort) (line infpred26 height100, sort) (line infpred27 height100, sort) (line infpred28 height100, sort) (line infpred29 height100, sort) (line infpred30 height100, sort) (line infpred31 height100, sort) (line infpred32 height100, sort) (line infpred33 height100, sort) (line infpred34 height100, sort) (line infpred35 height100, sort) (line infpred36 height100, sort) (line infpred37 height100, sort) (line infpred38 height100, sort), title("Infant mortality against mother height: lowess predictions") subtitle("38 Developing Countries") ytitle("Predicted IMR", margin(medlarge)) xtitle("Height, m") legend(off)

log close
exit